
<?php echo Html::script('media/js/jquery-1.9.1.js')?>
<script type="text/javascript">
$(document).ready(function(){
	$("#type").attr("disabled","disabled");
	$("#category").change(function(){
		$("#subcategory").attr("disabled","disabled");
		$("#subcategory").html("<option>wait...</option>");
		var id = $("#category option:selected").attr("value");
		var url = <?php echo '"'.URL::base().'search/select/"' ?>+id;
		$.ajax({
			url: url,
			type: 'post',
			success: function(data) {
			$("#subcategory").removeAttr("disabled");
			$("#subcategory").html(data);
			}
		});
	});
});
</script>

<?php echo Form::open('item/item/viewcategory/0', array('method' => 'get')); ?>
<select id="category" name="category">'
<?php
foreach ($categories as $category):
	echo '<option value="'.$category->id.'">'.$category->name.'</option>';
endforeach;
?>
</select>
<select id="subcategory" name="subcategory">
<option value="<?php echo $categories[0]->id ?>">All <?php echo $categories[0]->name;?></option>
<?php foreach ($categories[0]->subcategories->find_all() as $sub):?>
<?php echo '<option value='.$sub->id.'>'.$sub->name.'</option>';?>
<?php endforeach;?>
</select>
<?php echo Form::submit('submit', 'Search'); ?>
<?php echo Form::close(); ?>
<div id="result"></div>